package com.itycu.server.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: zhoucheng
 * @create: 2021-11-27 17:16
 **/
public class ListUtil {
    public static String listToString(List list, char separator) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < list.size(); i++) {
            if (i == list.size() - 1) {
                sb.append(list.get(i));
            } else {
                sb.append(list.get(i));
                sb.append(separator);
            }
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        List<Integer> ids = new ArrayList<>();
        ids.add(1);
        ids.add(2);
        System.out.println(ListUtil.listToString(ids,','));
    }
}
